﻿using DevExpress.XtraEditors;
using Shopfloormanagement;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Shopfloormanagement
{
    public partial class A3View : DevExpress.XtraEditors.XtraForm
    {
        public A3View()
        {
            InitializeComponent();
        }
        private Image CovertBase64ToImage(string base64String)//Base64转化为图片
        {
            try
            {
                // 将 Base64 字符串解码为字节数组
                byte[] imageBytes = Convert.FromBase64String(base64String);

                // 使用 MemoryStream 将字节数组转换为 Image 对象
                using (MemoryStream ms = new MemoryStream(imageBytes))
                {
                    Image image = Image.FromStream(ms);
                    return image;
                }
            }
            catch (Exception ex)
            {

                // 处理异常（例如 Base64 字符串格式错误）
                throw new Exception("Base64 字符串转换失败: " + ex.Message);
            }
        }
        //View功能实现
        //Date加载
        private void A3_List()
        {

            DataTable A3List = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_List", $"ID = '{rootcause.A3number}'");
            if (A3List.Rows.Count == 0) return; // 如果没有数据，直接返回
            labdate.Text = Convert.ToDateTime(A3List.Rows[0][16]).ToString("yyyy-MM-dd"); //日期
            labesponsible.Text = A3List.Rows[0][5].ToString();//责任人
            string A3ProblemStatement = A3List.Rows[0][4].ToString();//A3描述
            labA3ProblemStatement.Text = $" {A3ProblemStatement}";
        }//加载List信息
        private void A3_Step1()
        {

            DataTable A3Step1 = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_Step1", $"A3ReportNumberID = '{rootcause.A3number}'");
            if (A3Step1.Rows.Count == 0) return; // 如果没有数据，直接返回
            labmember1.Text = A3Step1.Rows[0][2].ToString();
            labmember2.Text = A3Step1.Rows[0][3].ToString();
            labmember3.Text = A3Step1.Rows[0][4].ToString();
            labmember4.Text = A3Step1.Rows[0][5].ToString();
            labmember5.Text = A3Step1.Rows[0][6].ToString();

        }//加载Step1信息
        private void A3_Step2()
        {
            DataTable A3Step2 = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_Step2", $"A3ReportNumberID = '{rootcause.A3number}'");
            if (A3Step2.Rows.Count == 0) return; // 如果没有数据，直接返回
            ISwhat.Text = A3Step2.Rows[0][2].ToString();
            ISwhere.Text = A3Step2.Rows[0][3].ToString();
            ISwhen.Text = A3Step2.Rows[0][4].ToString();
            IShow.Text = A3Step2.Rows[0][5].ToString();
            ISNOTwhat.Text = A3Step2.Rows[0][6].ToString();
            ISNOTwhere.Text = A3Step2.Rows[0][7].ToString();
            ISNOTwhen.Text = A3Step2.Rows[0][8].ToString();
            ISNOThow.Text = A3Step2.Rows[0][9].ToString();
            string picture1 = A3Step2.Rows[0][10].ToString();
            string picture2 = A3Step2.Rows[0][11].ToString();
            string picture3 = A3Step2.Rows[0][12].ToString();
            if (picture1 != "")
            {
                Image pic1image = CovertBase64ToImage(A3Step2.Rows[0][10].ToString());
                imgSlider.Images.Add(pic1image);
            }
            if (picture2 != "")
            {
                Image pic2image = CovertBase64ToImage(A3Step2.Rows[0][11].ToString());
                imgSlider.Images.Add(pic2image);
            }
            if (picture3 != "")
            {
                Image pic3image = CovertBase64ToImage(A3Step2.Rows[0][12].ToString());
                imgSlider.Images.Add(pic3image);
            }
        }//加载Step2信息
        private void A3_Step3()
        {
            step3pic1.Visible = false;
            step3pic2.Visible = false;
            step3pic3.Visible = false;
            DataTable A3Step3 = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_Step3", $"A3ReportNumberID = '{rootcause.A3number}'");
            if (A3Step3.Rows.Count == 0) return; // 如果没有数据，直接返回
            step3action1.Text = A3Step3.Rows[0][2].ToString();
            step3action2.Text = A3Step3.Rows[0][3].ToString();
            step3action3.Text = A3Step3.Rows[0][4].ToString();
            step3who1.Text = A3Step3.Rows[0][11].ToString();
            step3who2.Text = A3Step3.Rows[0][12].ToString();
            step3who3.Text = A3Step3.Rows[0][13].ToString();
            step3when1.Text = Convert.ToDateTime(A3Step3.Rows[0][20]).ToString("yyyy-MM-dd");
            step3when2.Text = Convert.ToDateTime(A3Step3.Rows[0][21]).ToString("yyyy-MM-dd");
            step3when3.Text = Convert.ToDateTime(A3Step3.Rows[0][22]).ToString("yyyy-MM-dd");
            string pic1 = A3Step3.Rows[0][29].ToString();
            string pic2 = A3Step3.Rows[0][30].ToString();
            string pic3 = A3Step3.Rows[0][31].ToString();
            if (step3action1.Text != "")
            {

                if (pic1 == "1")
                {
                    step3pic1.Visible = true;
                    step3pic1.Image = Properties.Resources.进度0;
                }
                else if (pic1 == "2")
                {
                    step3pic1.Visible = true;
                    step3pic1.Image = Properties.Resources.进度25;
                }
                else if (pic1 == "3")
                {
                    step3pic1.Visible = true;
                    step3pic1.Image = Properties.Resources.进度50;
                }
                else if (pic1 == "4")
                {
                    step3pic1.Visible = true;
                    step3pic1.Image = Properties.Resources.进度75;
                }
                else if (pic1 == "5")
                {
                    step3pic1.Visible = true;
                    step3pic1.Image = Properties.Resources.进度100;
                }
                else
                {
                    return;
                }
            }
            else
            {
                step3when1.Text = "";
            }    
            if (step3action2.Text != "")
            {

                if (pic2 == "1")
                {
                    step3pic2.Visible = true;
                    step3pic2.Image = Properties.Resources.进度0;
                }
                else if (pic2 == "2")
                {
                    step3pic2.Visible = true;
                    step3pic2.Image = Properties.Resources.进度25;
                }
                else if (pic2 == "3")
                {
                    step3pic2.Visible = true;
                    step3pic2.Image = Properties.Resources.进度50;
                }
                else if (pic2 == "4")
                {
                    step3pic2.Visible = true;
                    step3pic2.Image = Properties.Resources.进度75;
                }
                else if (pic2 == "5")
                {
                    step3pic2.Visible = true;
                    step3pic2.Image = Properties.Resources.进度100;
                }
                else
                {
                    return;
                }
            }
            else
            {
                step3when2.Text = "";
            }
            if (step3action3.Text != "")
            {

                if (pic3 == "1")
                {
                    step3pic3.Visible = true;
                    step3pic3.Image = Properties.Resources.进度0;
                }
                else if (pic3 == "2")
                {
                    step3pic3.Visible = true;
                    step3pic3.Image = Properties.Resources.进度25;
                }
                else if (pic3 == "3")
                {
                    step3pic3.Visible = true;
                    step3pic3.Image = Properties.Resources.进度50;
                }
                else if (pic3 == "4")
                {
                    step3pic3.Visible = true;
                    step3pic3.Image = Properties.Resources.进度75;
                }
                else if (pic3 == "5")
                {
                    step3pic3.Visible = true;
                    step3pic3.Image = Properties.Resources.进度100;
                }
                else
                {
                    return;
                }
            }
            else
            {
                step3when3.Text = "";
            }
            bool yes1 = Convert.ToBoolean(A3Step3.Rows[0][38]);
            bool yes2 = Convert.ToBoolean(A3Step3.Rows[0][39]);
            bool yes3 = Convert.ToBoolean(A3Step3.Rows[0][40]);
            step3yes1.Checked = yes1;
            step3yes2.Checked = yes2;
            step3yes3.Checked = yes3;
            bool no1 = Convert.ToBoolean(A3Step3.Rows[0][47]);
            bool no2 = Convert.ToBoolean(A3Step3.Rows[0][48]);
            bool no3 = Convert.ToBoolean(A3Step3.Rows[0][49]);
            step3no1.Checked = no1;
            step3no2.Checked = no2;
            step3no3.Checked = no3;
        }//加载Step3信息
        private void LoadDataAndUpdateControls()
        {
            // 从数据库中获取数据表
            DataTable A3Step5 = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_Step5", $"A3ReportNumberID = '{rootcause.A3number}'");

            if (A3Step5.Rows.Count > 0)
            {
                // 遍历表格中的每一行
                foreach (DataRow row in A3Step5.Rows)
                {
                    // 遍历 m1{i}, m2{i} ... m6{i} (i从1到5)
                    for (int group = 1; group <= 6; group++)
                    {
                        for (int i = 1; i <= 5; i++)
                        {
                            // 获取 LabelControl 和 PictureEdit 控件
                            LabelControl labelControl = (LabelControl)this.Controls.Find($"m{group}{i}", true).FirstOrDefault();
                            PictureEdit pictureEdit = (PictureEdit)this.Controls.Find($"p{group}{i}", true).FirstOrDefault();

                            if (labelControl != null && pictureEdit != null)
                            {
                                bool matchFound = false; // 记录是否匹配成功

                                // 遍历 Cause1 到 Cause9
                                for (int j = 1; j <= 9; j++)
                                {
                                    string causeColumn = $"Cause{j}";
                                    string directColumn = $"Direct{j}";
                                    string notColumn = $"Not{j}";
                                    string doubtfulColumn = $"Doubtful{j}";

                                    if (labelControl.Text == row[causeColumn].ToString()) // 如果匹配成功
                                    {
                                        int directValue = Convert.ToInt32(row[directColumn]);
                                        int notValue = Convert.ToInt32(row[notColumn]);
                                        int doubtfulValue = Convert.ToInt32(row[doubtfulColumn]);

                                        // 根据条件设置图片
                                        SetPictureBasedOnCondition(pictureEdit, directValue, notValue, doubtfulValue);

                                        matchFound = true;
                                        break; // 找到匹配后就跳出循环
                                    }
                                }

                                // 如果没有匹配到任何 Cause，隐藏 PictureEdit
                                if (!matchFound)
                                {
                                    pictureEdit.Visible = false;
                                }
                            }
                        }
                    }
                }
            }
        }
        // 根据条件判断并设置图片
        private void SetPictureBasedOnCondition(PictureEdit pictureEdit, int directValue, int notValue, int doubtfulValue)
        {
            pictureEdit.EditValue = null;

            if (directValue == 1)
            {
                pictureEdit.EditValue = Properties.Resources.对号; // B1 图片
            }
            else if (notValue == 1)
            {
                pictureEdit.EditValue = Properties.Resources.错号; // B2 图片
            }
            else if (doubtfulValue == 1)
            {
                pictureEdit.EditValue = Properties.Resources.问号; // B3 图片
            }

            // 如果没有图片，则隐藏控件
            pictureEdit.Visible = pictureEdit.EditValue != null;

            // 设置图片填充模式
            pictureEdit.Properties.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Stretch;
        }
        private void A3_Step4()
        {
            DataTable Fish = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_Step4", $"A3ReportNumberID = '{rootcause.A3number}'");
            if (Fish.Rows.Count == 0) return; // 如果没有数据，直接返回
            else { Fishbone.Text = Fish.Rows[0][2].ToString(); }
            DataRow row = Fish.Rows[0]; // 取第 0 行数据
            // 加载Man
            for (int i = 1; i <= 5; i++)
            {
                string columnName = $"Man{i}";

                // 确保列存在
                if (!Fish.Columns.Contains(columnName)) continue;

                // 获取 lablecontrol 控件
                Control[] controls = this.Controls.Find($"m1{i}", true);
                if (controls.Length > 0 && controls[0] is DevExpress.XtraEditors.LabelControl lablecontrol)
                {
                    // 赋值，忽略 NULL
                    lablecontrol.Text = row[columnName] != DBNull.Value ? row[columnName].ToString() : string.Empty;
                }
            }
            //加载Machine
            for (int i = 1; i <= 5; i++)
            {
                string columnName = $"Machine{i}";

                // 确保列存在
                if (!Fish.Columns.Contains(columnName)) continue;

                // 获取 lablecontrol 控件
                Control[] controls = this.Controls.Find($"m2{i}", true);
                if (controls.Length > 0 && controls[0] is DevExpress.XtraEditors.LabelControl lablecontrol)
                {
                    // 赋值，忽略 NULL
                    lablecontrol.Text = row[columnName] != DBNull.Value ? row[columnName].ToString() : string.Empty;
                }
            }
            //加载Material
            for (int i = 1; i <= 5; i++)
            {
                string columnName = $"Material{i}";

                // 确保列存在
                if (!Fish.Columns.Contains(columnName)) continue;

                // 获取 lablecontrol 控件
                Control[] controls = this.Controls.Find($"m3{i}", true);
                if (controls.Length > 0 && controls[0] is DevExpress.XtraEditors.LabelControl lablecontrol)
                {
                    // 赋值，忽略 NULL
                    lablecontrol.Text = row[columnName] != DBNull.Value ? row[columnName].ToString() : string.Empty;
                }
            }
            //加载Method
            for (int i = 1; i <= 5; i++)
            {
                string columnName = $"Method{i}";

                // 确保列存在
                if (!Fish.Columns.Contains(columnName)) continue;

                // 获取 lablecontrol 控件
                Control[] controls = this.Controls.Find($"m4{i}", true);
                if (controls.Length > 0 && controls[0] is DevExpress.XtraEditors.LabelControl lablecontrol)
                {
                    // 赋值，忽略 NULL
                    lablecontrol.Text = row[columnName] != DBNull.Value ? row[columnName].ToString() : string.Empty;
                }
            }
            //加载Mileu
            for (int i = 1; i <= 5; i++)
            {
                string columnName = $"Mileu{i}";

                // 确保列存在
                if (!Fish.Columns.Contains(columnName)) continue;

                // 获取 lablecontrol 控件
                Control[] controls = this.Controls.Find($"m5{i}", true);
                if (controls.Length > 0 && controls[0] is DevExpress.XtraEditors.LabelControl lablecontrol)
                {
                    // 赋值，忽略 NULL
                    lablecontrol.Text = row[columnName] != DBNull.Value ? row[columnName].ToString() : string.Empty;
                }
            }
            //加载Measurement
            for (int i = 1; i <= 5; i++)
            {
                string columnName = $"Measurement{i}";

                // 确保列存在
                if (!Fish.Columns.Contains(columnName)) continue;

                // 获取 lablecontrol 控件
                Control[] controls = this.Controls.Find($"m6{i}", true);
                if (controls.Length > 0 && controls[0] is DevExpress.XtraEditors.LabelControl lablecontrol)
                {
                    // 赋值，忽略 NULL
                    lablecontrol.Text = row[columnName] != DBNull.Value ? row[columnName].ToString() : string.Empty;
                }
            }
            LoadDataAndUpdateControls();
        }//加载Step4信息
        private void A3_Step6()
        {
            step6pic1.Visible = false;
            step6pic2.Visible = false;
            step6pic3.Visible = false;
            step6pic4.Visible = false;
            step6pic5.Visible = false;
            DataTable A3Step6 = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_Step6", $"A3ReportNumberID = '{rootcause.A3number}'");
            if (A3Step6.Rows.Count == 0) return; // 如果没有数据，直接返回
            step6action1.Text = A3Step6.Rows[0][11].ToString();
            step6action2.Text = A3Step6.Rows[0][12].ToString();
            step6action3.Text = A3Step6.Rows[0][13].ToString();
            step6action4.Text = A3Step6.Rows[0][14].ToString();
            step6action5.Text = A3Step6.Rows[0][15].ToString();
            bool picyes1 = Convert.ToBoolean(A3Step6.Rows[0][38]);
            bool picyes2 = Convert.ToBoolean(A3Step6.Rows[0][39]);
            bool picyes3 = Convert.ToBoolean(A3Step6.Rows[0][40]);
            bool picyes4 = Convert.ToBoolean(A3Step6.Rows[0][41]);
            bool picyes5 = Convert.ToBoolean(A3Step6.Rows[0][42]);
            bool picno1 = Convert.ToBoolean(A3Step6.Rows[0][47]);
            bool picno2 = Convert.ToBoolean(A3Step6.Rows[0][48]);
            bool picno3 = Convert.ToBoolean(A3Step6.Rows[0][49]);
            bool picno4 = Convert.ToBoolean(A3Step6.Rows[0][50]);
            bool picno5 = Convert.ToBoolean(A3Step6.Rows[0][51]);
            if (step6action1.Text != "")
            {

                if (picyes1 == true && picno1 == false)
                {
                    step6pic1.Visible = true;
                    step6pic1.Image = Properties.Resources.对号;
                }
                else if (picyes1 == false && picno1 == true)
                {
                    step6pic1.Visible = true;
                    step6pic1.Image = Properties.Resources.错号;
                }
                else
                {
                    return;
                }

            }
            if (step6action2.Text != "")
            {

                if (picyes2 == true && picno2 == false)
                {
                    step6pic2.Visible = true;
                    step6pic2.Image = Properties.Resources.对号;
                }
                else if (picyes2 == false && picno2 == true)
                {
                    step6pic2.Visible = true;
                    step6pic2.Image = Properties.Resources.错号;
                }
                else
                {
                    return;
                }

            }
            if (step6action3.Text != "")
            {

                if (picyes3 == true && picno3 == false)
                {
                    step6pic3.Visible = true;
                    step6pic3.Image = Properties.Resources.对号;
                }
                else if (picyes3 == false && picno3 == true)
                {
                    step6pic3.Visible = true;
                    step6pic3.Image = Properties.Resources.错号;
                }
                else
                {
                    return;
                }

            }
            if (step6action4.Text != "")
            {

                if (picyes4 == true && picno4 == false)
                {
                    step6pic4.Visible = true;
                    step6pic4.Image = Properties.Resources.对号;
                }
                else if (picyes4 == false && picno4 == true)
                {
                    step6pic4.Visible = true;
                    step6pic4.Image = Properties.Resources.错号;
                }
                else
                {
                    return;
                }

            }
            if (step6action5.Text != "")
            {

                if (picyes5 == true && picno5 == false)
                {
                    step6pic5.Visible = true;
                    step6pic5.Image = Properties.Resources.对号;
                }
                else if (picyes5 == false && picno5 == true)
                {
                    step6pic5.Visible = true;
                    step6pic5.Image = Properties.Resources.错号;
                }
                else
                {
                    return;
                }

            }

        }//加载Step6信息
        private void A3_Step6_5why()
        {
            DataTable A3Step6_5why = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_Step6_5Why", $"A3ReportNumberID = '{rootcause.A3number}'");
            if (A3Step6_5why.Rows.Count == 0) return; // 如果没有数据，直接返回
            string step6potentialrootcause1 = A3Step6_5why.Rows[0][2].ToString();
            string step6potentialrootcause2 = A3Step6_5why.Rows[0][3].ToString();
            bool result1 = Convert.ToBoolean(A3Step6_5why.Rows[0][24]);
            bool result2 = Convert.ToBoolean(A3Step6_5why.Rows[0][25]);
            if (result1 == true && result2 == true)
            {
                step6potentialrootcause.Text = $" 主要原因：{step6potentialrootcause1}\n 次要原因：{step6potentialrootcause2}";
                why1.Text = A3Step6_5why.Rows[0][4].ToString();
                why2.Text = A3Step6_5why.Rows[0][5].ToString();
                why3.Text = A3Step6_5why.Rows[0][6].ToString();
                why4.Text = A3Step6_5why.Rows[0][7].ToString();
                why5.Text = A3Step6_5why.Rows[0][8].ToString();
                because1.Text = A3Step6_5why.Rows[0][14].ToString();
                because2.Text = A3Step6_5why.Rows[0][15].ToString();
                because3.Text = A3Step6_5why.Rows[0][16].ToString();
                because4.Text = A3Step6_5why.Rows[0][17].ToString();
                because5.Text = A3Step6_5why.Rows[0][18].ToString();
                step6rootcause.Text = A3Step6_5why.Rows[0][2].ToString();
            }
            if (result1 == true && result2 == false)
            {
                step6potentialrootcause.Text = $" {step6potentialrootcause1}";
                why1.Text = A3Step6_5why.Rows[0][4].ToString();
                why2.Text = A3Step6_5why.Rows[0][5].ToString();
                why3.Text = A3Step6_5why.Rows[0][6].ToString();
                why4.Text = A3Step6_5why.Rows[0][7].ToString();
                why5.Text = A3Step6_5why.Rows[0][8].ToString();
                because1.Text = A3Step6_5why.Rows[0][14].ToString();
                because2.Text = A3Step6_5why.Rows[0][15].ToString();
                because3.Text = A3Step6_5why.Rows[0][16].ToString();
                because4.Text = A3Step6_5why.Rows[0][17].ToString();
                because5.Text = A3Step6_5why.Rows[0][18].ToString();
                step6rootcause.Text = A3Step6_5why.Rows[0][2].ToString();
            }
            if (result1 == false && result2 == true)
            {
                step6potentialrootcause.Text = $" {step6potentialrootcause2}";
                why1.Text = A3Step6_5why.Rows[0][9].ToString();
                why2.Text = A3Step6_5why.Rows[0][10].ToString();
                why3.Text = A3Step6_5why.Rows[0][11].ToString();
                why4.Text = A3Step6_5why.Rows[0][12].ToString();
                why5.Text = A3Step6_5why.Rows[0][13].ToString();
                because1.Text = A3Step6_5why.Rows[0][19].ToString();
                because2.Text = A3Step6_5why.Rows[0][20].ToString();
                because3.Text = A3Step6_5why.Rows[0][21].ToString();
                because4.Text = A3Step6_5why.Rows[0][22].ToString();
                because5.Text = A3Step6_5why.Rows[0][23].ToString();
                step6rootcause.Text = A3Step6_5why.Rows[0][3].ToString();
            }
            if (result1 == false && result2 == false)
            {
                step6potentialrootcause.Text = "";
            }
        }//加载Step6_5why信息
        private void A3_Step7()
        {
            DataTable A3Step7 = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_Step7", $"A3ReportNumberID = '{rootcause.A3number}'");
            if (A3Step7.Rows.Count == 0) return; // 如果没有数据，直接返回
            for (int i = 1; i <= 9; i++)
            {
                string resultCol = "ResultYes" + i;
                string actionCol = "Action" + i;
                string infoCol = "Information" + i;

                // 确保列存在并且值为 true
                if (A3Step7.Columns.Contains(resultCol) && A3Step7.Rows[0][resultCol] != DBNull.Value &&
                    Convert.ToBoolean(A3Step7.Rows[0][resultCol]))
                {
                    string actionText = A3Step7.Rows[0][actionCol]?.ToString() ?? "";
                    string infoText = A3Step7.Rows[0][infoCol]?.ToString() ?? "";

                    Step7rootcause.Text = $" 验证措施: {actionText}\n 验证结果: {infoText}";
                    Step7rootcause.Appearance.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
                    Step7rootcause.AutoSizeMode = DevExpress.XtraEditors.LabelAutoSizeMode.None;

                    break; // 找到第一个为 true 的就停止
                }
            }

        }//加载Step7信息
        private void A3_Step8()
        {
            step8pic1.Visible = false;
            step8pic2.Visible = false;
            step8pic3.Visible = false;
            step8pic4.Visible = false;
            DataTable A3Step8 = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_Step8", $"A3ReportNumberID = '{rootcause.A3number}'");
            if (A3Step8.Rows.Count == 0) return; // 如果没有数据，直接返回
            step8action1.Text = A3Step8.Rows[0][2].ToString();
            step8action2.Text = A3Step8.Rows[0][3].ToString();
            step8action3.Text = A3Step8.Rows[0][4].ToString();
            step8action4.Text = A3Step8.Rows[0][5].ToString();
            step8who1.Text = A3Step8.Rows[0][11].ToString();
            step8who2.Text = A3Step8.Rows[0][12].ToString();
            step8who3.Text = A3Step8.Rows[0][13].ToString();
            step8who4.Text = A3Step8.Rows[0][14].ToString();
            step8when1.Text = Convert.ToDateTime(A3Step8.Rows[0][20]).ToString("yyyy-MM-dd");
            step8when2.Text = Convert.ToDateTime(A3Step8.Rows[0][21]).ToString("yyyy-MM-dd");
            step8when3.Text = Convert.ToDateTime(A3Step8.Rows[0][22]).ToString("yyyy-MM-dd");
            step8when3.Text = Convert.ToDateTime(A3Step8.Rows[0][23]).ToString("yyyy-MM-dd");
            string pic1 = A3Step8.Rows[0][29].ToString();
            string pic2 = A3Step8.Rows[0][30].ToString();
            string pic3 = A3Step8.Rows[0][31].ToString();
            string pic4 = A3Step8.Rows[0][32].ToString();
            if (step8action1.Text != "")
            {

                if (pic1 == "1")
                {
                    step8pic1.Visible = true;
                    step8pic1.Image = Properties.Resources.进度0;
                }
                else if (pic1 == "2")
                {
                    step8pic1.Visible = true;
                    step8pic1.Image = Properties.Resources.进度25;
                }
                else if (pic1 == "3")
                {
                    step8pic1.Visible = true;
                    step8pic1.Image = Properties.Resources.进度50;
                }
                else if (pic1 == "4")
                {
                    step8pic1.Visible = true;
                    step8pic1.Image = Properties.Resources.进度75;
                }
                else if (pic1 == "5")
                {
                    step8pic1.Visible = true;
                    step8pic1.Image = Properties.Resources.进度100;
                }
                else
                { 
                    return;
                }
            }
            else
            {
                step8when1.Text = "";
            }
            if (step8action2.Text != "")
            {

                if (pic2 == "1")
                {
                    step8pic2.Visible = true;
                    step8pic2.Image = Properties.Resources.进度0;
                }
                else if (pic2 == "2")
                {
                    step8pic2.Visible = true;
                    step8pic2.Image = Properties.Resources.进度25;
                }
                else if (pic2 == "3")
                {
                    step8pic2.Visible = true;
                    step8pic2.Image = Properties.Resources.进度50;
                }
                else if (pic2 == "4")
                {
                    step8pic2.Visible = true;
                    step8pic2.Image = Properties.Resources.进度75;
                }
                else if (pic2 == "5")
                {
                    step8pic2.Visible = true;
                    step8pic2.Image = Properties.Resources.进度100;
                }
                else
                {
                    return;
                }
            }
            else
            {
                step8when2.Text = "";
            }
            if (step8action3.Text != "")
            {

                if (pic3 == "1")
                {
                    step8pic3.Visible = true;
                    step8pic3.Image = Properties.Resources.进度0;
                }
                else if (pic3 == "2")
                {
                    step8pic3.Visible = true;
                    step8pic3.Image = Properties.Resources.进度25;
                }
                else if (pic3 == "3")
                {
                    step8pic3.Visible = true;
                    step8pic3.Image = Properties.Resources.进度50;
                }
                else if (pic3 == "4")
                {
                    step8pic3.Visible = true;
                    step8pic3.Image = Properties.Resources.进度75;
                }
                else if (pic3 == "5")
                {
                    step8pic3.Visible = true;
                    step8pic3.Image = Properties.Resources.进度100;
                }
                else
                {
                    return;
                }
            }
            else
            {
                step8when3.Text = "";
            }
            if (step8action4.Text != "")
            {

                if (pic4 == "1")
                {
                    step8pic4.Visible = true;
                    step8pic4.Image = Properties.Resources.进度0;
                }
                else if (pic4 == "2")
                {
                    step8pic4.Visible = true;
                    step8pic4.Image = Properties.Resources.进度25;
                }
                else if (pic4 == "3")
                {
                    step8pic4.Visible = true;
                    step8pic4.Image = Properties.Resources.进度50;
                }
                else if (pic4 == "4")
                {
                    step8pic4.Visible = true;
                    step8pic4.Image = Properties.Resources.进度75;
                }
                else if (pic4 == "5")
                {
                    step8pic4.Visible = true;
                    step8pic4.Image = Properties.Resources.进度100;
                }
                else
                {
                    return;
                }
            }
            else
            {
                step8when4.Text = "";
            }
            bool yes1 = Convert.ToBoolean(A3Step8.Rows[0][38]);
            bool yes2 = Convert.ToBoolean(A3Step8.Rows[0][39]);
            bool yes3 = Convert.ToBoolean(A3Step8.Rows[0][40]);
            bool yes4 = Convert.ToBoolean(A3Step8.Rows[0][41]);
            step8yes1.Checked = yes1;
            step8yes2.Checked = yes2;
            step8yes3.Checked = yes3;
            step8yes4.Checked = yes4;
            bool no1 = Convert.ToBoolean(A3Step8.Rows[0][47]);
            bool no2 = Convert.ToBoolean(A3Step8.Rows[0][48]);
            bool no3 = Convert.ToBoolean(A3Step8.Rows[0][49]);
            bool no4 = Convert.ToBoolean(A3Step8.Rows[0][50]);
            step8no1.Checked = no1;
            step8no2.Checked = no2;
            step8no3.Checked = no3;
            step8no4.Checked = no4;
        }//加载Step8信息
        private void A3_Step9()
        {
            DataTable A3Step9 = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_Step9", $"A3ReportNumberID = '{rootcause.A3number}'");
            if (A3Step9.Rows.Count == 0) return; // 如果没有数据，直接返回
            step9.Text = A3Step9.Rows[0][2].ToString();
        }
        private void A3View_Load(object sender, EventArgs e)
        {
            A3_List();
            A3_Step1();
            A3_Step2();
            A3_Step3();
            A3_Step4();
            A3_Step6();
            A3_Step6_5why();
            A3_Step7();
            A3_Step8();
            A3_Step9();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("是否确定关闭报告？", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                bool reslist2 = LSQL.SQL.Update(SystemInfo.SQL, "A3_List", "A3Status = 0", $"ID = '{rootcause.A3number}'");
                if (reslist2)
                {
                    MessageBox.Show("A3报告已确认关闭", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                    rootcause frm = new rootcause();
                    frm.Show();
                }

            }
                
        }
    }
}